﻿using ChinaAdd.DataBase;
using ChinaAdd.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace ChinaAdd.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ProviceCityChinaController : ControllerBase
    {
        private readonly EFCoreDbContext _dbContext;

        public ProviceCityChinaController(EFCoreDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        /// <summary>
        /// 获取地址数据
        /// </summary>
        /// <param name="pCode">父级id</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAsync([FromQuery] long pCode = 0)
        {
            try
            {
                List<ProvinceCityChina> provinceCityChinas = _dbContext.provinceCityChinas.Where(c => c.ParentId == pCode).ToList();
                return Ok(new { status = true, message = "查询成功", data = provinceCityChinas });
            }
            catch (Exception ex)
            {
                return Ok(new { status = false, message = "查询异常：" + ex.Message, data = ex });
            }
        }
    }
}
